package com.xiaoma.tpo.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.User;
import com.xiaoma.tpo.domain.UserFriend;

@Repository
public class UserFriendDao extends BaseDaoImpl<UserFriend>{

    public List<User> findFriends(int userId, int type) {
        String sql = "select a.* from user as a left join user_friend as b on a.id=b.friend_id where b.user_id=?";
        if (type != 1) {//被加为朋友
            sql = "select a.* from user as a left join user_friend as b on a.id=b.user_id where b.friend_id=?";
        }
        List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(User.class, getNameHandler()), userId);
        return (List<User>)list;
    }
}
